package com.c1802.dao.Impl;

import com.c1802.dao.UserDao;
import com.c1802.entity.User;
import com.c1802.util.AliPool;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;

public class UserDaoImpl  implements UserDao {

    QueryRunner runner = new QueryRunner();
    @Override
    public User login(String uname, String upass) throws SQLException {
        String sql="select * from users where uname=? and upass=?";
        Connection conn= AliPool.getConn();
        User user=runner.query(conn,sql,new BeanHandler<User>(User.class),uname,upass);
        conn.close();
        return user;
    }

    @Override
    public int UpdateUser(int id,String uname, String upass) throws SQLException {
        String sql="update users set uname=?,upass=? where id=?";
        Connection conn=AliPool.getConn();
        int num=runner.update(conn,sql,uname,upass,id);
        conn.close();
        return num;
    }

    @Override
    public int UpdateUserImage(int id, String image) throws SQLException {
        String sql="update users set img=? where id=?";
        Connection conn=AliPool.getConn();
        int num=runner.update(conn,sql,image,id);
        conn.close();conn.close();
        return num;
    }
}
